﻿using System;

namespace HSS.ComponentModel
{
	/// <summary>
	/// Indicates whether the name of the associated property is displayed with parentheses in the Properties window. This class cannot be inherited.
	/// </summary>
	[AttributeUsage(AttributeTargets.All)]
	public sealed class ParenthesizePropertyNameAttribute : Attribute
	{
		#region Fields
		/// <summary>
		/// Initializes a new instance of the ParenthesizePropertyNameAttribute class with a default value that indicates that the associated property should not be shown with parentheses. This field is read-only.
		/// </summary>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
		public static readonly ParenthesizePropertyNameAttribute Default = new ParenthesizePropertyNameAttribute();
		private bool needParenthesis;
		#endregion

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="ParenthesizePropertyNameAttribute"/> class that indicates that the associated property should not be shown with parentheses.
		/// </summary>
		public ParenthesizePropertyNameAttribute()
			: this(false)
		{
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="ParenthesizePropertyNameAttribute"/> class, using the specified value to indicate whether the attribute is displayed with parentheses.
		/// </summary>
		/// <param name="needParenthesis">true if the name should be enclosed in parentheses; otherwise, false. </param>
		public ParenthesizePropertyNameAttribute(bool needParenthesis)
		{
			this.needParenthesis = needParenthesis;
		}
		#endregion

		#region Properties
		/// <summary>
		/// Gets a value indicating whether the Properties window displays the name of the property in parentheses in the Properties window.
		/// </summary>
		public bool NeedParenthesis
		{
			get
			{
				return this.needParenthesis;
			}
		}
		#endregion

		#region Overrides
		/// <summary>
		/// Compares the specified object to this object and tests for equality.
		/// </summary>
		/// <param name="obj">The object to be compared.</param>
		/// <returns>true if equal; otherwise, false.</returns>
		public override bool Equals(object obj)
		{
			var po = obj as ParenthesizePropertyNameAttribute;
			return ((null != po) && (po.NeedParenthesis == this.needParenthesis));
		}
		/// <summary>
		/// Gets the hash code for this object.
		/// </summary>
		/// <returns>The hash code for the object the attribute belongs to.</returns>
		public override int GetHashCode()
		{
			return base.GetHashCode();
		}
		#endregion

		#region Methods
		/// <summary>
		/// Gets a value indicating whether the current value of the attribute is the default value for the attribute.
		/// </summary>
		/// <returns>true if the current value of the attribute is the default value of the attribute; otherwise, false.</returns>
		public bool IsDefaultAttribute()
		{
			return this.Equals(Default);
		}
		#endregion
	}
}
